// 服务单工单流程业务规则
import {
  mobileReg,
  spaceCh,
  areaReg,
  mobileReg2,
  numberReg,
  dateReg,
  timeReg,
  dateTimeReg
} from "@/utils/reg";
const typeToPrice = {//安装细分对应单价
  DS: 115,
  SS: 200,
  KS: 105,
  L: 100,
  GS: 80,
  FGS: 0,
  KP: 30
};

export default {
  FlowNo: "009",
  formRules: function(vm) {
    return {
      TB_reworkId: {
        validator(rule, value, callback) {
          console.log("value", value);
          if (vm.form["DDL_serviceType"] == 2) {
            if (value && numberReg.test(value)) {
              callback();
            } else {
              callback("请填写正确的返修源单号");
            }
          } else {
            callback();
          }
        },
        trigger: "blur"
      },
      TB_telephone: {
        validator(rule, value, callback) {
          if (mobileReg.test(value)) {
            callback();
          } else {
            callback("请输入正确的手机号");
          }
        }
      },
      TB_time: {
        validator(rule, value, callback) {
          if (dateTimeReg.test(value)) {
            callback();
          } else {
            callback("请选择预约时间");
          }
        }
      },
    };
  },
  valueChange(vm, obj) {
    switch (obj.key) {
      case "DDL_serviceType": {
        let value = obj.value;
        if (value != 2) {
          console.log(vm.$refs);
          vm.$refs["reworkId"][0].resetValidate();
          vm.$refs["reworkId"][0].options.isEnable = 0;
        } else {
          vm.$refs["reworkId"][0].options.isEnable = 1;
        }
        break;
      }
      case "DDL_serviceSegmentation": {
        if (typeToPrice.hasOwnProperty(obj.value)) {
          vm.form.TB_servicePrice = `${typeToPrice[obj.value]}`;
        }
        break;
      }
      case "DDL_serviceTime": {
        vm.form.TB_dutyTime = obj.value;
        break;
      }
      case "TB_dutyTime": {
        vm.$set(vm.form,"TB_dutyTime",obj.value)
        break;
      }
    }
  },
  init(vm) {
    if (vm.form.DDL_serviceType != 2 && vm.$refs["reworkId"]) {
      vm.$refs["reworkId"][0].options.isEnable = 0;
    }
    if (vm.form.DDL_serviceSegmentation) {
      if (typeToPrice.hasOwnProperty(vm.form.DDL_serviceSegmentation)) {
        vm.form.TB_servicePrice = `${typeToPrice[vm.form.DDL_serviceSegmentation]}`;
      }
    }
  }
};
